package appVeterinaria.servlets;


import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import appVeterinaria.negocio.GestionPaciente;
import appVeterinaria.excepcion.*;

/**
 * Servlet implementation class PacienteInsertarServlet
 */
@WebServlet("/PacienteInsertarServlet")
public class PacienteInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PacienteInsertarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		int idCli = Integer.parseInt(request.getParameter("id_cliente"));
		String nom = request.getParameter("nombre");
		String esp = request.getParameter("especie");
		String raz = request.getParameter("raza");
		String gen = request.getParameter("genero");
		String tipsan = request.getParameter("tipo_sangre");
		String esterilz = request.getParameter("esterilizado");
		//boolean esterilz = Boolean.parseBoolean(request.getParameter("esterilizado"));
		String tam = request.getParameter("tamano");
		//double tam =  Double.parseDouble(request.getParameter("tamano"));
		String actv = request.getParameter("actividad");
		double pes =  Double.parseDouble(request.getParameter("peso"));
		String fecnaci = request.getParameter("fecha_nacimiento");
		
		
		GestionPaciente negocio = new GestionPaciente();
		try {
			negocio.insertar(idCli, nom, esp, raz, gen, tipsan, esterilz, tam, actv, pes, fecnaci);
			response.sendRedirect(request.getContextPath()	+ "/PacienteBuscarServlet");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}


